package com.app.manage.moudles.system.contoller;

import com.app.manage.moudles.system.dao.TLogDao;
import com.app.manage.moudles.system.entity.TLog;
import com.app.manage.utils.Rsp;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("log")
public class LogController {

    @Resource
    private TLogDao logDao;

    @PostMapping("listLog")
    public Rsp listLog(@RequestBody TLog log){
        LambdaQueryWrapper<TLog> query = new LambdaQueryWrapper<>();
        query.like(StringUtils.isNotEmpty(log.getLogName()),TLog::getLogName,log.getLogName());
        query.eq(log.getLogType() !=null,TLog::getLogType,log.getLogType());
        query.eq(log.getRelId() != null,TLog::getRelId,log.getRelId());
        query.orderByDesc(TLog::getStartTime);
        return Rsp.success(logDao.selectList(query));
    }
}
